const path = require('path');
const webpack = require('webpack');
const HtmlPlugin = require('html-webpack-plugin');
// const nodeExternals = require('webpack-node-externals');
 module.exports = {
    devtool: 'source-map',
    entry: {
        index: './dist/index.jsx'
    },
    resolve: {
        extensions: ['.json', '.js', '.jsx']
    },
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'build')
    },
    module: {
        rules: [{
            test: /\.css$/,
            loader:['style-loader', 'css-loader']
        }, {
            test: /\.scss$/,
            loader: ['style-loader', 'css-loader', 'sass-loader']
        }, {
            test: /\.(png|svg|jpg|gif)$/,
            use:[
                {
                    loader:"url-loader",
                    options:{
                        limit:50000,   //表示低于50000字节（50K）的图片会以 base64编码
                        name:'[name].[hash:7].[ext]',
                    }
                },
            ]
        }, {
            test: /\.(js|jsx)$/,
            loader: ['eslint-loader', 'babel-loader'],
            exclude: /node_modules/
        }]
    },
    devServer: {
        historyApiFallback: true,
        contentBase: './build',
        port: 8081,
        inline: true,
        hot: true
    },
    // externals: [nodeExternals()],
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new HtmlPlugin({
            template: './src/index.html'
        })
    ]
}